package com.ssm.song.book.controller;

import cn.hutool.core.codec.Base64;
import com.ssm.song.book.domain.Reader;
import com.ssm.song.book.domain.vo.ReaderVo;
import com.ssm.song.book.service.IBookService;
import com.ssm.song.book.service.IReaderService;
import com.ssm.song.book.util.Result;
import com.ssm.song.book.util.StatusCode;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author 宋伟宁
 * @Date 2023/10/16
 * @Version 1.0
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private IReaderService readerService;

    @PostMapping("/register")
    public Result register(@RequestBody  Reader reader) {
         return  this.readerService.register(reader)
                 ? new Result(StatusCode.OK,"注册成功",true)
                 : new Result(StatusCode.ERROR,"注册失败",false);

    }

    @PostMapping("/login")
    public Result login(String cardnum,String password){
          ReaderVo vo=this.readerService.login(cardnum,password);
          return  vo!=null ? new Result(StatusCode.OK,"登录成功",true,vo)
                  : new Result(StatusCode.LOGIN_ERROR,"登录失败",false);

    }

}
